home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / tests / rawecho / rawecho.c < prev   
Encoding:
C/C++ Source or Header  |  1992-03-25  |  934 b   |  59 lines

  1. #include <sgtty.h>
  2. #include <stdio.h>
  3. #include <sys/file.h>
  4.  
  5. struct sgttyb ttyInfo;
  6.  
  7. void PutOne();
  8.  
  9. main()
  10. {
  11.     int tty;
  12.     char buf[10];
  13.     int charsRead;
  14.     char *bufPtr;
  15.  
  16.     tty = open("/dev/console", O_RDONLY, 0666);
  17.     if (tty < 0) {
  18.     perror("can't open tty");
  19.     exit(1);
  20.     }
  21.     if (gtty(tty, &ttyInfo) < 0) {
  22.     perror("can't get tty info");
  23.     exit(1);
  24.     }
  25.     ttyInfo.sg_flags |= RAW;
  26.     if (stty(tty, &ttyInfo) < 0) {
  27.     perror("can't set raw mode");
  28.     exit(1);
  29.     }
  30.  
  31.     while ((charsRead = read(tty, buf, sizeof(buf))) >= 0) {
  32.     if (charsRead == 0) {
  33.         fprintf(stderr, ".");
  34.         sleep(1);
  35.         continue;
  36.     }
  37.     for (bufPtr = buf; bufPtr < buf+charsRead; bufPtr++) {
  38.         PutOne(*bufPtr);
  39.     }
  40.     if (buf[0] == '?') {
  41.         break;
  42.     }
  43.     }
  44.  
  45.     ttyInfo.sg_flags &= ~RAW;
  46.     if (stty(tty, &ttyInfo) < 0) {
  47.     perror("can't reset tty");
  48.     }
  49.  
  50.     exit(0);
  51. }
  52.  
  53. void
  54. PutOne(ch)
  55.     int ch;
  56. {
  57.     fprintf(stderr, " 0%o ", ch);
  58. }
  59.